using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Markup;
using Common;

namespace SettingsView
{
	public partial class NewNameWindow : Window, IComponentConnector
	{
		public ObservableCollection<string> Items { get; set; }

		public NewNameWindow()
		{
			InitializeComponent();
		}

		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			if (textBoxName.Text.Length == 0)
			{
				MessageBox.Show(Utility.GetMessage("msg_null_list_value"));
				textBoxName.Focus();
				textBoxName.SelectAll();
			}
			else if (Items != null && Items.Where((string s) => s == textBoxName.Text).Count() > 0)
			{
				MessageBox.Show(string.Format(Utility.GetMessage("msg_list_value_isexist"), textBoxName.Text));
				textBoxName.Focus();
				textBoxName.SelectAll();
			}
			else
			{
				base.DialogResult = true;
				Close();
			}
		}

		public string GetNewName()
		{
			return textBoxName.Text;
		}

		private void textBoxName_Loaded(object sender, RoutedEventArgs e)
		{
			textBoxName.Focus();
		}
	}
}
